﻿//********************************************************************************//
//创建日期：<创建日期，2016-10-13>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：收费管理 进入下一水量年月
//********************************************************************************//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using System.Text;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.ShouFeiGL
{
    public partial class JinRuXYSLNY : BasePage
    {
        #region 属性

        #endregion

        #region 变量
        /// <summary>
        /// 存储过程执行类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        /// <summary>
        /// 参数bll
        /// </summary>
        QS_CANSHUBBLL _CANSHUBLL = new QS_CANSHUBBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
        }

        /// <summary>
        /// 差错检查
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaCuo_Click(object sender, EventArgs e)
        {
            int wtype = BusinessTool.WType;
            //验证该水量年月是否有帐单未打印
            int i_l = 1;

            //string result = "0";
            //_SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 1, out result);
            //if (Convert.ToInt32(result) > 0)
            //{
            //    PageTools.AlertMsg(this, "该水量年月仍有帐单未打印！");
            //    return;
            //}

            //验证现在抄表数据是否允许修改
            //string mingcheng = wtype == 2 ? "IsCanModifyCopyData" : "IsCanModifyCopyData2";
            //DataTable dt = _CANSHUBLL.SelectQS_CANSHUBsDynamic(string.Format("S_MINGCHENG='{0}' AND I_JLZT=0", mingcheng), null);
            //int zhi = Convert.ToInt32(dt.Rows[0]["S_ZHI"]);
            //if (zhi==1)
            //{
            //    PageTools.AlertMsg(this, "现在抄表数据允许修改，请先设置为不可修改状态");
            //    return;
            //}
            //验证水量年月是否已开帐
            i_l = 2;
            DataTable dt2 = _SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 2).Tables[0];
            if (Convert.ToInt32(dt2.Rows[0][0]) == 0)
            {
                PageTools.AlertMsg(this, "该水量年月还没有开帐！");
                return;
            }
            //验证是否存在有户无表
            i_l = 3;
            DataTable dt3 = _SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 3).Tables[0];

            if (Convert.ToInt32(dt3.Rows.Count) > 0)
            {
                string msg = "";
                for (int i = 0; i < dt3.Rows.Count; i++)
                {
                    msg += "," + dt3.Rows[i]["S_YONGHUH"].ToString();
                }
                PageTools.AlertMsg(this, "存在有户无表的用户，请检查！" + msg);
                return;
            }
            //验证是否存在井下无表数据
            i_l = 4;
            DataTable dt4 = _SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 4).Tables[0];
            if (Convert.ToInt32(dt4.Rows.Count) > 0)
            {
                string msg = "";
                for (int i = 0; i < dt4.Rows.Count; i++)
                {
                    msg += "," + dt4.Rows[i]["S_JINGBH"].ToString();
                }
                PageTools.AlertMsg(this, "存在井下无表的数据，请检查！" + msg);
                return;
            }

            //验证是否存在没有开帐的表
            // i_l = 5;
            // DataTable dt5 = _SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 5).Tables[0];
            // if (Convert.ToInt32(dt5.Rows.Count) > 0)
            //{
            //    string msg = "";
            //    for (int i = 0; i < dt5.Rows.Count; i++)
            //    {
            //        msg += "," + dt5.Rows[i]["S_SHUIBIAOBH"].ToString();
            //    }
            //    PageTools.AlertMsg(this, "存在没有开帐的表，不能进入下一水量年月" + msg);
            //    return;
            //}

            //--验证账单是否打印完成
            DataTable dt6 = _SpHelper.P_QSSF_JINRUXYSLNY_YZ(wtype, 6).Tables[0];
            if (dt6.Rows.Count > 0 && dt6.Rows[0][0].ToString() == "0")
            {
                PageTools.AlertMsg(this, "该水量年月帐单已打印完毕");
            }
            else
            {
                PageTools.AlertMsg(this, "该水量年月帐单未打印");
                return;
            }

            btnXiaYiSLNY.Enabled = true;

        }

        /// <summary>
        /// 进入下一水量年月
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnXiaYiSLNY_Click(object sender, EventArgs e)
        {
            //进入下一水量年月
            int wtype=BusinessTool.WType;
            int caozuor=LoginInfo.CurrentUser.UserID;
            int ym = Convert.ToInt32(txtV.Text);
            int zry = DateTime.Now.Year;
            int zrm = DateTime.Now.Month;
            if ((ym / 100) >= zry && (ym % 100) >= zrm)
            {
                PageTools.AlertMsg(this, "当前水量年月不能大于自然年月");
                return;
            }
            string result="";
            _SpHelper.P_QSSF_JINRUXYSLNY(wtype, caozuor, out result);
            if (result=="1")
            {
                PageTools.AlertMsg(this, "操作成功");
                btnXiaYiSLNY.ClientEnabled = false;
            }
            txtV.Text = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            int wtype = BusinessTool.WType;
            txtV.Text = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
            
        }
        #endregion        

    }
}